﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using WorkBasket.Data.Entities;
using WorkBasket.Data.Repository;
using WorkBasket.Infrastructure;
using WorkBasket.Models;

namespace WorkBasket.Controllers.Api
{
    [Authorize]
    public class InstanceController : ApiController
    {

        private SOC soc = new SOC(new MyContext());
        [HttpPost]
        [Route("api/instance/save")]
        public IHttpActionResult Post([FromBody] Instance value)
        {

            bool WasNew = false;
            try
            {
                if (value.InstanceID == 0)
                {
                    soc.Instances.Add(value);
                                            
                    WasNew = true;


                }
                else
                {
                    soc.Instances.Update(value);
                }

                soc.CommitChanges();
                if(WasNew){


               //if its new create the workflow path.  Used sproc for performance

                }
                return Json(new DataReturn(string.Empty, value));
            }
            catch (Exception e)
            {
                return new System.Web.Http.Results.ExceptionResult(e, this);
            }
        }
    }
}
